var playerNum = 1;
var playerIDtext = 'previewPLayer';
var playerID = playerIDtext + playerNum;
var playerHTMLbegin = '<div class = "videoPreviewDiv"><div class = "beforeGetVideo"></div><video id="';
var playerHTMLend = '" class="video-js vjs-default-skin" preload="auto" width="142" height="80" data-setup="{}"> <source src="" type="video/mp4"></video></div>';
var timer;

$(function() {
	 _V_.options.flash.swf = "/js/video-js.swf";
	$('#all_pages').on('mouseenter', '.peMopho', function(){
		clearTimeout(timer);
		var peMopho = $(this);
		timer = setTimeout(function() {
			//$(this).append('<div class = "beforeGetVideo"></div>');
			if (peMopho.find('.videoPreviewDiv').size() == 0)
			{
				playerID = playerIDtext + playerNum;
				peMopho.append(playerHTMLbegin + playerID + playerHTMLend);
				playerNum++;
				if (peMopho.attr('video-file'))
					$('#' + playerID + ' source').attr('src', peMopho.attr('video-file'));
				else
					$('#' + playerID + ' source').attr('src', '/preview/54085179/54085179.mp4');
			}
			else
				playerID = peMopho.find('.videoPreviewDiv .video-js').attr('id');
				
			peMopho.find('.beforeGetVideo').show();
			
			$('#' + playerID).parents('.videoPreviewDiv').fadeIn('slow');
			
			setTimeout(function() {
				peMopho.find('.beforeGetVideo').hide();
				_V_(playerID).ready(function(){
					//$('#' + playerID).parents('.videoPreviewDiv').fadeIn('slow');
					var myPlayer = this;
					myPlayer.volume(0)
					myPlayer.play();			
				});
				var myPlayer = _V_(playerID);
				myPlayer.volume(0)
				myPlayer.play();
			}, 2000);
		}, 250);
	})
	$('#all_pages').on('mouseleave', '.peMopho', function()
	{
		clearTimeout(timer);
		_V_(playerID).pause();
		$('#' + playerID).parents('.videoPreviewDiv').fadeOut('slow');
		//$(this).find('.beforeGetVideo').remove();
	});
});